import { EXPIRE_CODE } from '@/api/config'
interface Error {
  code: number | string
  message: string
}
export const errorHandler = (error: Error) => {
  if (error.code === EXPIRE_CODE) {
    // $popError('token过期，请重新登录')
    // clearStorage()
    setTimeout(() => {
      window.location.href = '/'
    }, 300)
  } else {
    // $popError(error.message)
  }
  return Promise.reject(error)
}

export const headerHandler = (config: any) => {
  const token = localStorage.getItem('token')
  if (token) {
    config.headers.Authorization = `Bearer ${token}`
  }
  return config
}
